<?

class MySitesCron
{
	public $ZoneType='crontab';
	public $dialogs=array();
	
	function addDialog($target,$event)
	{
		array_push($this->dialogs,array('target'=>$target,'event'=>$event));
	}
	
	function run() {
		global $options, $riaZoneType;
		$riaZoneType = $this->ZoneType;
		$options['logger']['log_files_dir'].='/crontab';
		if (! is_dir($options['smarty']['compile_dir'].'/crontab')) {
			mkdir($options['smarty']['compile_dir'].'/crontab');
		}
		
		$_SERVER['SERVER_NAME'] = str_replace('http://','',$options['site']['base_url']);
		$_GET['lang_code'] = 'ru';
		
		# Preparsing
		$RewriteManager = new RewriteManager();
		$RewriteManager->run();
   		
        if (count($this->dialogs)) {
        	foreach ($this->dialogs as $item) {
				$class ='Dialog_'.$item['target'];
				$dialog= new $class;
				$dialog->RewriteManager = $RewriteManager;
				
				$dialog->forcePrepare=true;
				$dialog->silent=true;
				$dialog->RewriteManager->target = $item['target']; 
				$dialog->RewriteManager->event = $item['event']; 
				#print "Ok: ".$dialog->event."\n";
				#print "Ok: ".$dialog->target."\n";
				#print $DIALOG_CLASS."\n";
				#$dialog->prepare();
				$dialog->handleRequest();
        	}
        }
	}
	
}
?>